<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>WISSC轮滑教培服务网-查询系统</title>
    <#assign base=request.contextPath  />
    <link rel="icon" href="${base}/favicon.ico">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <link rel="stylesheet" href="${base}/frame/layui/css/layui.css?t=1534970980648" media="all">
    <script type="text/javascript" src="${base}/js/feng.js"></script>
    <script src="${base}/frame/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="${base}/js/zhang.js"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery.ztree.excheck.js"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery.ztree.exedit.js"></script>
    <link rel="stylesheet" href="${base}/css/demo.css" type="text/css">
    <link rel="stylesheet" href="${base}/css/zTreeStyle.css" type="text/css">
    <style type="text/css">
        form {
            padding: 10px;
        }

        .layui-btn-radius {
            border-radius: 3px;
        }
    </style>
</head>
<body>
<form class="layui-form">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label"><a style="color:red">*</a>&nbsp;用户名</label>
            <div class="layui-input-inline">
                <input name="username" id="username" lay-verify="required" autocomplete="off" class="layui-input isNull"
                       type="text">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label"><a style="color:red">*</a>&nbsp;密码</label>
            <div class="layui-input-inline">
                <input name="password" id="password" lay-verify="required" autocomplete="off" class="layui-input isNull"
                       type="text">
            </div>
            <div class="layui-form-mid layui-word-aux">请填写6到12位密码</div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label"><a style="color:red">*</a>&nbsp;审核</label>
            <div class="layui-input-block">
                <select name="qualifications" lay-verify="required" id="status" class=" isNull">
                    <option value="">请选择</option>
                    <option value="1">需审核</option>
                    <option value="2">不需审核</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div style="height: 300px;width:450px;">
            <label class="layui-form-label"><i style="color:red">*</i>选择该角色可见菜单</label>
            <ul id="tree" class="ztree"
                style="width:300px; height: 280px; overflow:auto;border:1px solid #F0F9FF;background-color: #F0F9FF;"></ul>
        </div>
    </div>

    <div class="layui-form-item" style="margin-left: 30px">
        <div class="layui-input-inline">
            <button class="layui-btn" lay-submit lay-filter="formDemo" lay-submit="" type="button"
                    onclick="onInsert()" style="background-color: #0092EF;">立即提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
    </div>
</form>

<script>

    layui.use(['form', 'layedit', 'laydate', 'layer'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;
    });

    var zTreeObj,
        setting = {

            view: {
                selectedMulti: false,
                showLine: true,
                dblClickExpand: false
            },

            callback: {
                //回调函数 默认展开节点
                onAsyncSuccess:
                    function () {
                        var treeObj = $.fn.zTree.getZTreeObj("tree");
                        treeObj.expandAll(true);
                    }

            },
            async: {
                enable: true,
                url: "${base}/menu/findPermission"
            },
            data: {
                simpleData: {
                    enable: true,
                    idKey: "id",
                    pIdKey: "pId",
                    rootPid: 0
                }
            },
            check: {
                enable: true,
                chkStyle: "checkbox",
                radioType: "all",
                chkboxType: {"Y": "ps", "N": "ps"}
            }

        };
    //初始化树
    zTreeObj = $.fn.zTree.init($("#tree"), setting);


    //添加
    function onInsert() {
        if ($("#username").val() == "") {
            return;
        }
        if ($("#password").val() == "") {
            return;
        }
        if ($("#status").val() == "") {
            return;
        }
        if (getAllID("tree") == "") {
            layer.msg("请选择该角色可见菜单！");
            return;
        }
        var password = $("#password").val();
        var reg = /^[a-z0-9_-]{6,18}$/;
        if (!reg.test(password)) {
            layer.msg("必须是6-12位密码")
            return;
        }
        var requestJson = {};
        requestJson.menuId = getAllID("tree");
        requestJson.username = $("#username").val();
        requestJson.password = $("#password").val();
        requestJson.status = $("#status").val();
        $.ajax({
            type: "POST", //提交方式
            url: "${base}/user/saveUser",//路径
            dataType: "json",
            data: requestJson,
            success: function (data) {//返回数据根据结果进行相应的处理
                if (data.code === 0) {
                    layer.msg("添加成功,请到用户查询模块查看");
                    setTimeout(function () {
                        window.location.href = "${base}/user/user_add.html"
                    }, 1500)
                } else {
                    layer.msg("添加失败");
                }
            }
        });
    }
</script>
</body>
</html>
